package com.xzit.rcpyxt.service.impl;

import com.xzit.rcpyxt.dto.ClassDto;
import com.xzit.rcpyxt.dto.TeacherClassListRequest;
import com.xzit.rcpyxt.dto.TeacherDto;
import com.xzit.rcpyxt.entity.Class;
import com.xzit.rcpyxt.entity.TeacherClass;
import com.xzit.rcpyxt.mapper.ClassMapper;
import com.xzit.rcpyxt.mapper.TeacherClassMapper;
import com.xzit.rcpyxt.service.ClassService;
import com.xzit.rcpyxt.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {

    @Autowired
    private ClassMapper classMapper;
    @Autowired
    private TeacherClassMapper teacherClassMapper;

    @Override
    public PageUtil findByClassList(ClassDto classDto) {
        int page = classDto.getPage();
        int pageSize = classDto.getPageSize();
        classDto.setPage(page - 1);
        classDto.setPageSize(page * pageSize);
        List<Class> teachers = classMapper.selectByClassList(classDto);
        int totalElements = classMapper.countByClassList(classDto);
        return new PageUtil(page, pageSize, totalElements, teachers);
    }

    @Override
    public PageUtil findByTeacherClassList(TeacherClassListRequest teacherClassListRequest) {
        int page = teacherClassListRequest.getPage();
        int pageSize = teacherClassListRequest.getPageSize();
        teacherClassListRequest.setPage(page - 1);
        teacherClassListRequest.setPageSize(page * pageSize);
        List<TeacherClass> teachers = teacherClassMapper.selectByTeacherClassList(teacherClassListRequest);
        int totalElements = teacherClassMapper.countByTeacherClassList(teacherClassListRequest);
        return new PageUtil(page, pageSize, totalElements, teachers);
    }

}
